//
//  WHZSportingViewController.m
//  WHZGuDong
//
//  Created by whz on 16/11/9.
//  Copyright © 2016年 whz. All rights reserved.
//

#import "WHZSportingViewController.h"
#import "WHZSportsMapViewController.h"
#import <Masonry.h>

@interface WHZSportingViewController ()

@property(nonatomic, weak)WHZSportsMapViewController *mapViewController;

@end



@implementation WHZSportingViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    
    // MARK: - 设置地图视图控制器
    [self setupMapViewController];
}

#pragma mark - 设置地图视图控制器界面
- (void)setupMapViewController {
    
    WHZSportsMapViewController *mapVc = [WHZSportsMapViewController new];
    self.mapViewController = mapVc;
    
    [self addChildViewController:mapVc];
    
    [self.view addSubview:mapVc.view];
    
//    mapVc.view.frame = self.view.bounds;
    [mapVc.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom).offset(-160);
    }];

    NSLog(@"\n%@\n%@",self.view, mapVc.view);
    
    // MARK: - 设置运动轨迹模型
    mapVc.sportTracking = [[WHZSportsHomeTracking alloc] initWithType:self.sportType state:WHZSportsStateContinue];
    
    // MARK: - 完成控制器的添加
    [mapVc didMoveToParentViewController:self];
    
    // MARK: - 创建 暂停、继续、结束button
    UIButton *buttonPause = [[UIButton alloc] init];
    [buttonPause setTitle:@"暂停" forState:UIControlStateNormal];
    [buttonPause setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
    [buttonPause.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [self.view addSubview:buttonPause];
    [buttonPause mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(mapVc.view.mas_left).offset((self.view.bounds.size.width-self.view.center.x)/2);
        make.bottom.equalTo(self.view.mas_bottom).offset(-70);
    }];
    buttonPause.tag = 0;
    [buttonPause addTarget:self action:@selector(changeSportState:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *buttonContinue = [[UIButton alloc] init];
    [buttonContinue setTitle:@"继续" forState:UIControlStateNormal];
    [buttonContinue setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
    [buttonContinue.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [self.view addSubview:buttonContinue];
    [buttonContinue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.bottom.equalTo(self.view.mas_bottom).offset(-70);
    }];
    buttonContinue.tag = 1;
    [buttonContinue addTarget:self action:@selector(changeSportState:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *buttonOver = [[UIButton alloc] init];
    [buttonOver setTitle:@"结束" forState:UIControlStateNormal];
    [buttonOver setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
    [buttonOver.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [self.view addSubview:buttonOver];
    [buttonOver mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-(self.view.bounds.size.width-self.view.center.x)/2);
        make.bottom.equalTo(self.view.mas_bottom).offset(-70);
    }];
    buttonOver.tag = 2;
    [buttonOver addTarget:self action:@selector(changeSportState:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - 监听方法 (改变运动状态)
/**
 修改运动状态的方法

 @param sender 按钮
 */
- (void)changeSportState:(UIButton *)sender {

    _mapViewController.sportTracking.sportsState = sender.tag;
    
}

@end
